<template>
  <uni-popup id="popup" ref="popup1" :type="type_status" :animation="true">
			<view class="" style="background-color: #FFFFFF;padding:20upx 30upx 0;border-radius: 20upx;width: 500rpx;">
				<view
					style="text-align: center;height: 100upx;line-height: 100upx;color: #333333;font-weight: 600;font-size: 32rpx;">
					提示
				</view>
				<view class="popup-content" style="text-align: center;font-size: 28upx;">请授权您的手机号</view>
				<view class="footer">
					<button @click="quxiao1"
						style="flex: 1;background-color: #f3f3f3;color: #333333;margin-right: 20rpx;font-weight: 600;"
						type="default">取消</button>
					<button @getphonenumber="login1" style="flex: 1;background-color: #000000;color: #FFFFFF;"
						open-type="getPhoneNumber">确定</button>
				</view>
			</view>
		</uni-popup>
</template>

<script>
export default {
  name: 'wechatPhoneLogin',

  data() {
    return {
      type_status: 'center',
    }
  },

  mounted() {

  },

  methods: {
    login1: function(e) {
      console.log(e)
      let that = this
      this.$refs.popup1.close()
      // #ifdef MP-WEIXIN
      uni.login({
        provider: 'weixin',
        success: (code) => {
          console.log(code)
          this.post('api/wechat/phone', {
            code: code.code,
            iv: e.detail.iv,
            encryptedData: e.detail.encryptedData
          }, true).then(res => {
            console.log(res, '123455')
            if (res.code == 1) {
              uni.setStorageSync('mobile', res.data.phoneNumber)
              uni.setStorageSync('mobile2',res.data.mobile2)
              that.user()
            }else{
              uni.showToast({
                title: res.msg,
                icon: "none",
                duration: 1000
              })
            }
          })
        }
      })
      // #endif
      // #ifdef APP-PLUS || H5
      uni.navigateTo({
        url:'/subpages/pages/xgmp?isUserInfo=1',
      })
      // #endif

    },
    quxiao: function () {
      this.$refs.popup.close()
    },
    async open() {
      if (uni.getStorageSync('mobile') == null || uni.getStorageSync('mobile') == '') {
        this.$refs.popup1.open()
        return false
      }
      return true
    }
  },
}
</script>
<style lang="scss">
.footer {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid #f4f4f4;
  margin-top: 30rpx;
  padding-bottom: 20rpx;

  button {
    margin: 0 auto;
    width: 100%;
    background-color: #19be6b;
    // width: 200upx;
    border-radius: 10upx;
    font-size: $uni-font-size-sm;
    // padding: 22upx 34upx;
    height: 80upx;
    font-size: 30rpx;
    line-height: 80upx !important;
    // line-height: 1;
    color: #ffffff;
  }

  button:after {
    border: 0;
  }
}
</style>